//
//  ACNavigationController.m
//  ACLiteAVUISDK
//
//  Created by 冯琰琰 on 2021/3/29.
//

#import "ACNavigationController.h"
#import "ACLiveFileListViewController.h"

@interface ACNavigationController ()

@end

@implementation ACNavigationController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setNavigationBarStyle];
}

-(void)setNavigationBarStyle{
    [self.navigationBar setTranslucent:NO];
    [self setAutomaticallyAdjustsScrollViewInsets:NO];
    [self.navigationBar setShadowImage:[[UIImage alloc] init]];
}

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{
    [self.topViewController setHidesBottomBarWhenPushed:YES];
    [super pushViewController:viewController animated:animated];
    [self.viewControllers[0] setHidesBottomBarWhenPushed:NO];
    if (self.childViewControllers.count > 1) {
        UIButton *leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        leftBtn.frame = CGRectMake(0, 0, 32, 32);
        [leftBtn setImage:[UIImage imageWithName:@"icon_left_back" bundle:ACLiteAVUISDK targetClass:[self class]] forState:UIControlStateNormal];
        UIBarButtonItem *leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftBtn];
        viewController.navigationItem.leftBarButtonItem = leftBarButtonItem;
        @weakify(self);
        [[leftBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
            @strongify(self)
            if ([viewController isKindOfClass: ACLiveFileListViewController.class]) {
                ACLiveFileListViewController *fileVC = (ACLiveFileListViewController *)viewController;
                fileVC.selectedHandler(fileVC.selectedArray);
            }
            [self popViewControllerAnimated:YES];
        }];
    }
}

@end
